package com.es.service.impl;

import com.es.entity.IdCard;
import com.es.entity.Person;
import com.es.mapper.IdCardMapper;
import com.es.mapper.PersonMapper;
import com.es.mybatis.util.MybatisUtils;
import com.es.service.PersonService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 描述:
 * MyBatis-
 *
 * @author Derek
 * 创建时间：2022-05-09 10:26
 */
public class PersonServiceImpl implements PersonService {

    @Override
    public void save(Person person) {
        SqlSession session = MybatisUtils.getSqlSession(false);
        PersonMapper mapper = session.getMapper(PersonMapper.class);
        IdCardMapper idCardMapper = session.getMapper(IdCardMapper.class) ;
        //

        int i = idCardMapper.insert(person.getIdCard());
        int j = mapper.insert(person);
        session.commit();
        session.close();

        System.out.println(i+j);
    }

    @Override
    public Person get(Integer id) {
        SqlSession session = MybatisUtils.getSqlSession();
        PersonMapper mapper = session.getMapper(PersonMapper.class);
        Person person = mapper.get(id);
        session.close();
        return person;

    }

    @Override
    public List<Person> list() {
        SqlSession session = MybatisUtils.getSqlSession();
        PersonMapper mapper = session.getMapper(PersonMapper.class);
        return mapper.list();
    }
}
